/**
 * 测试线程相关函数；pthread_create,pthread_self
 * @author: sundx
 * @date: 2020-05-24 03:20:35
 * @Last Modified by: sundx
 * @Last Modified time: 2020-05-27 15:13:03
 */
#include <iostream>
#include <pthread.h>
#include <unistd.h>
void *demo(void *m);
void outError(const char *errorMessage);
int main() {
  pthread_t tid;
  int ret;
  std::cout << "pid: " << getpid() << " tid: " << pthread_self() << std::endl;
  ret = pthread_create(&tid, NULL, demo, nullptr);
  if (ret != 0) {
    outError("pthread failed");
  }
  sleep(1); // 等待线程
  return 0;
}
void *demo(void *m) {
  std::cout << "pid: " << getpid() << " tid: " << pthread_self() << std::endl;
  return nullptr;
}
void outError(const char *errorMessage) {

  std::cout << errorMessage << std::endl;
  exit(EXIT_FAILURE);
}